<?php
$my_report = "c:\\CrystalReport2.rpt";
$my_pdf = "c:\\Report31.pdf";
$ObjectFactory= new COM("CrystalReports11.ObjectFactory.1") or die ("Error on load"); // call COM port
$crapp = $ObjectFactory-> CreateObject("CrystalDesignRunTime.Application"); // create an instance for Crystal
$creport = $crapp->OpenReport($my_report, 1);
$crapp->LogOnServer("crdb_odbc.dll","mySQLODB","ob","root","sa");
//------ Set database logon info ------
//echo ($creport->Database->Tables(1)->SetLogOnInfo("localhost:3306","ob",  "root", "sa");
//echo ($creport->Database->Tables->Item(1)->ConnectionProperties['DSN']) ;
 //foreach ($creport->Database->Tables->Item(1)->ConnectionProperties as $key => $val){
//	echo $key ." - " . $val . "<br>"; 
//
 //}  
 //   'CRrep.Database.Tables(i).SetLogonInfo "dsn"   'optional:  ,"DB Name", "User ID", "Password"
 //$creport->Database->Tables(1)->SetLogOnInfo("mySQLODB", "",  "root", "sa");
// echo $creport->Database->Tables->Item(1)->LogOnServerName ."<br>";
// echo $creport->Database->Tables->Item(1)->LogOnDatabaseName   ."<br>";
// echo $creport->Database->Tables->Item(1)->LogOnUserID  ."<br>";
// echo $creport->Database->Tables->Item(1)->Location   ."<br>";
// echo $creport->Database->Tables->Item(1)->TestConnectivity()   ."<br>";
// $creport->Database->Tables->Item(1)->ConnectionProperties['DSN'] = "";
  // $creport->Database->Tables->Item(1)->ConnectionProperties['User ID'] = "root";
 // $creport->Database->Tables->Item(1)->ConnectionProperties['Password']= "sa";
 //$creport->FormulaSyntax = 0;

$creport->EnableParameterPrompting = 0;

$creport->DiscardSavedData();
//$creport->ReadRecords();

$creport->ParameterFields(1)->SetCurrentValue ("Chonburi");

//export to PDF process
$creport->ExportOptions->DiskFileName=$my_pdf; //export to pdf
$creport->ExportOptions->PDFExportAllPages=true;
$creport->ExportOptions->DestinationType=1; // export to file
$creport->ExportOptions->FormatType=31; // PDF type
$creport->Export(false);

$len = filesize($my_pdf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=".$my_pdf);
readfile($my_pdf);

//------ Release the variables ------
$creport = null;
$crapp = null;
$ObjectFactory = null;

?>